You Don-t Know JS Types by Grammar
Author:Grammar
Format: epub
Published: 0101-01-01T00:00:00+00:00
SomeType x = SomeType( y )
Wouldn’t you generally agree that we simplified the type conversion here to reduce the unnecessary “noise” of the intermediate conversion step? I mean, is it really all that important, right here at this point in the code, to see and deal with the fact that y goes to AnotherType first before then going to SomeType?
Some would argue, at least in some circumstances, yes. But I think an equal argument can be made of many other circumstances that here, the simplification actually aids in the readability of the code by abstracting or hiding away such details, either in the language itself or in our own abstractions.
Undoubtedly, behind the scenes, somewhere, the intermediate conversion step is still happening. But if that detail is hidden from view here, we can just reason about getting y to type SomeType as an generic operation and hide the messy details.
While not a perfect analogy, what I’m going to argue throughout the rest of this chapter is that JS implicit coercion can be thought of as providing a similar aid to your code.
But, and this is very important, that is not an unbounded, absolute statement. There are definitely plenty of evils lurking around implicit coercion that will harm your code much more than any potential readability improvements. Clearly, we have to learn how to avoid such constructs so we don’t poison our code with all manner of bugs.
Many developers believe that if a mechanism can do some useful thing A but can also be abused or misused to do some awful thing Z, then we should throw out that mechanism altogether, just to be safe.
My encouragement to you is: don’t settle for that. Don’t “throw the baby out with the bathwater.” Don’t assume implicit coercion is all bad because all you think you’ve ever seen is its “bad parts.” I think there are “good parts” here, and I want to help and inspire more of you to find and embrace them!
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(14836)
The Mikado Method by Ola Ellnestam Daniel Brolund(12087)
Hello! Python by Anthony Briggs(12000)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(11398)
Dependency Injection in .NET by Mark Seemann(11178)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10528)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(10001)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(9621)
Grails in Action by Glen Smith Peter Ledbrook(9321)
Hit Refresh by Satya Nadella(9039)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(8926)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(8816)
The Kubernetes Operator Framework Book by Michael Dame(8473)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(8376)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8295)
Robo-Advisor with Python by Aki Ranin(8248)
Practical Computer Architecture with Python and ARM by Alan Clements(8223)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(8193)
Building Low Latency Applications with C++ by Sourav Ghosh(8097)